<template>
  <el-select
    v-model="customerValue"
    clearable
    :placeholder="dataList.Placeholder"
    @change="change"
  >
    <el-option
      v-for="item in customerList"
      :key="item.id"
      :label="item.customerName"
      :value="item.id"
    >
    </el-option>
  </el-select>
</template>

<script>
import {getList} from "@/ModuleSysBusiness/api/SysBusiness/Customer.js";
export default {
  name: "CustomerList",
  components: {},
  props: {
    // 查询条件下是否需要全部
    isAll: {
      type: Boolean,
      default: false,
    },
    // 使用id或者使用code绑定
    value: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      customerList: [],
      customerValue: this.value,
    };
  },
  computed: {
    dataList() {
      return this.$t("ModuleDevice.Device");
    },
  },
  watch: {
    value(val) {
      this.customerValue = val;
    },
  },
  mounted() {
    this.initData();
  },
  methods: {
    change() {
      this.$emit("input", this.customerValue);
    },
    initData() {
      getList({ customerName: "" }, { pageIndex: 1, pageSize: 10000 })
        .then((res) => {
          this.customerList = res.data.dataList;

          if (this.isAll) {
            var obj = {};
            obj.id = -1;
            obj.value = -1;
            obj.customerName = "全部";
            this.customerList.unshift(obj);
          }
        });
    },
  },
};
</script>
<style scoped></style>
